package com.scut.fy.admin.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.scut.fy.admin.mapper.SysRoleMapper;
import com.scut.fy.admin.model.entity.SysRole;
import com.scut.fy.admin.model.entity.SysUser;
import com.scut.fy.admin.service.ISysRoleService;
import com.scut.fy.common.core.util.Assert;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author jy
 * @since 2021-09-04
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Resource
    private SysRoleMapper sysRoleMapper;

    @Override
    public List<SysRole> getRolesByUser(SysUser sysUser) {
        Assert.notNull(sysUser, "sysUser不能为空");
        if (sysUser.getUserId() != null) {
            return sysRoleMapper.getRolesByUserId(sysUser.getUserId());
        }
        if (sysUser.getUserName() != null) {
            return sysRoleMapper.getRolesByUserName(sysUser.getUserName());
        }
        return null;
    }
}
